require.config({
    paths: {
        'jquery': ['http://cdn.bootcss.com/jquery/2.2.4/jquery.min', '/js/lib/jquery.min'],
        'bootstrap': '/js/lib/bootstrap.min'
    },
    shim: {
        'bootstrap': ['jquery'],
    }
});

require(['jquery', 'common', 'bootstrap'], function($, common) {
    $(function() {
        $('#loginForm').on('submit', function(event) {
            event.preventDefault();
            var data = {};
            data.account = $('#accountInput').val();
            data.password = $('#passwordInput').val();
            $.post(common.urlBase + '/account/login.json', data, function(result) {

                if (result.ok) {
                    sessionStorage.setItem('role', result.data.role);
                    sessionStorage.setItem('token', result.data.token);
                    if (result.data.school_id) {
                        sessionStorage.setItem('school_id', result.data.school_id);
                    }
                    if (result.data.name) {
                        sessionStorage.setItem('name', result.data.name);
                    }
                    window.location.href = '/views/trade_query.html';
                } else {
                    console.log('fail');
                    $('#noticeMsg').html('登录失败~请重试');
                    $('#noticeModal').modal('show');
                }
            }, 'json');
        });
    });
});
